import instance from "./instance";

/* 通用的增POST 删DELETE 改PUT 查GET  */

/* 通用的POST请求 */
export function doPost(url, data, config) {
    return instance.post(url, data, config).catch((err) => console.log("err=", err));
}

/* 通用的GET请求 */
// /movie/playings?page=3&pagesize=10
// doGet("/movie/playings",{page:3,pagesize:10})
export function doGet(url, dataObj, config,defaultInstance = instance) {
    /* {page:3,pagesize:10} => ?page=3&pagesize=10 */
    if (dataObj) {
        let searchParamStr = "?"
        for (let key in dataObj) {
            searchParamStr += `${key}=${dataObj[key]}`
        }
        url += searchParamStr
    }
    // console.log("url=",url);

    return defaultInstance.get(url, config).catch((err) => console.log("err=", err));
}